home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / COPYB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  715 b   |  37 lines

  1. /* copyb.c - copy a file with fscanf/fprintf  */
  2. #include "stdio.h"
  3.  
  4. main(argc,argv)
  5.     int argc ;
  6.     char  *argv[]  ;
  7.     {
  8.      FILE  *in ,
  9.           *out ;
  10.      char c ;
  11.      int nr ;
  12.      long n ;
  13.  
  14.      if( argc < 3 )
  15.           { printf(" USAGE - copy2 input-file output-file \n");
  16.         exit(0)  ;
  17.           }
  18.  
  19.      in   =  fopen(argv[1],"r");
  20.      out  =  fopen(argv[2],"w");
  21.      if(  ( in == NULL ) || ( out == NULL )  )
  22.           { printf("Cant open a file");
  23.         exit(0) ;
  24.           }
  25.  
  26.      n   =    0L  ;
  27.      nr  =    fscanf( in,"%c",c);
  28.      while( nr > 0 )
  29.           { n = n + 1 ;
  30.         fprintf(out,"%c",c)  ;
  31.         nr  = fscanf(in,"%c",&c)  ;
  32.           }  ;
  33.      fclose(in)  ;
  34.      fclose(out) ;
  35.      printf(" %1d characters copied",n) ;
  36.     }
  37.